package com.aifast.system.sys.dao;

import com.aifast.system.sys.entity.SysAuthorities;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jfinal.kit.Kv;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 权限 Mapper 接口
 * </p>
 *
 * @author fujian
 * @since 2022-01-07
 */
@Mapper
public interface SysAuthoritiesDao extends BaseMapper<SysAuthorities> {

    @Select("SELECT a.id,IF(LENGTH(a.authority) > 0,CONCAT_WS(\" \",a.`name`,a.authority),a.`name`) as `name`,a.authority,a.pid as pId,ra.id as checked,IF(a.pid = 0,true,FALSE) as `open` FROM sys_authorities a \n" +
            "LEFT JOIN sys_role_authority ra ON a.id = ra.authority_id AND ra.role_id = #{roleId} \n" +
            "WHERE a.deleted = 0 \n" +
            "GROUP BY a.id\n" +
            "ORDER BY a.sort DESC")
    List<Kv> getAuthTree(Integer roleId);
}
